package com.adjaisd.scarecrow.testJava;

import com.adjaisd.scarecrow.entity.Device;
import com.adjaisd.scarecrow.mapper.DeviceMapper;
import com.adjaisd.scarecrow.service.DeviceService;
import com.adjaisd.scarecrow.vo.Pager;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;

import java.util.Date;

@SpringBootTest
public class testDevice {

    @Autowired
    DeviceService deviceService;

    @Test
    void addDeviceData() throws InterruptedException {
        int beg = 1;
        for (int i = 0; i < 50; i++) {
            long idx = beg + i;
            long time = new Date().getTime();
            Device device = new Device(null, 10000L + idx, "树莓派" + idx, "这是树莓派" + idx + "号", time, "", 1L);
            deviceService.addDevice(device);
            Thread.sleep(20);
        }
    }

    @Autowired
    DeviceMapper deviceMapper;

    @Test
    void testGetDeviceByQuota() {
        long userId = 1L;
        String quotaName = "温度";
        String unit = "℃";
        Pager<Device> deviceByQuota =
                deviceService.getDeviceByQuota(userId, quotaName, unit, 1, 10);
        for (Device device : deviceByQuota.getItems()) {
            System.out.println(device);
        }
    }
}
